﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;

namespace MiladiShamsi
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private int YearM;
        private int MonthM;
        private int DayM;

        private int YearS;
        private int MonthS;
        private int DayS;

        public Window1()
        {
            InitializeComponent();
        }

        private string ConvertShamsiMonth(int currentMonth)
        {
            switch(currentMonth)
            {
                case 1:
                    return "فروردين";
                    break;
                case 2:
                    return "ارديبهشت";
                    break;
                case 3:
                    return "خرداد";
                    break;
                case 4:
                    return "تير";
                    break;
                case 5:
                    return "مرداد";
                    break;
                case 6:
                    return "شهريور";
                    break;
                case 7:
                    return "مهر";
                    break;
                case 8:
                    return "آبان";
                    break;
                case 9:
                    return "آذر";
                    break;
                case 10:
                    return "دي";
                    break;
                case 11:
                    return "بهمن";
                    break;
                case 12:
                    return "اسفند";
                    break;
                default:
                    return "اشتباه";
            }
        }

        private string ConvertMiladiMonth(int currentMonth)
        {
            switch (currentMonth)
            {
                case 1:
                    return "January";
                    break;
                case 2:
                    return "February";
                    break;
                case 3:
                    return "March";
                    break;
                case 4:
                    return "April";
                    break;
                case 5:
                    return "May";
                    break;
                case 6:
                    return "June";
                    break;
                case 7:
                    return "July";
                    break;
                case 8:
                    return "August";
                    break;
                case 9:
                    return "September";
                    break;
                case 10:
                    return "October";
                    break;
                case 11:
                    return "November";
                    break;
                case 12:
                    return "December";
                    break;
                default:
                    return "Error";
            }
        }

        private string ConvertShamsiDayOfWeek(DayOfWeek currentDay)
        {

            int currentDayint=(int)(currentDay);
            if (currentDayint == 0)
            {
                return "يک شنبه";
            }
            else if(currentDayint == 1)
            {
                return "دو شنبه";
            }
            else if(currentDayint == 2)
            {
                return "سه شنبه";
            }
            else if(currentDayint == 3)
            {
                 return "چهار شنبه";
            }
            else if(currentDayint == 4)
            {
                return "پنج شنبه";
            }
            else if(currentDayint == 5)
            {
                return "جمعه";
            }
            else if (currentDayint == 6)
            {
                return "شنبه";
            }
            else
            {
                return "اشتباه";
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DateTime currentDate=DateTime.Today;

            TextBoxYearMiladiConverted.Text = currentDate.Year.ToString();
            TextBoxMonthMiladiConverted.Text = ConvertMiladiMonth(currentDate.Month);
            TextBoxDayInMonthMiladiConverted.Text =currentDate.Day.ToString();
            TextBoxDayInWeekMiladiConverted.Text = currentDate.DayOfWeek.ToString();

            PersianCalendar pc=new PersianCalendar();

            TextBoxYearShamsiConverted.Text = pc.GetYear(currentDate).ToString();
            TextBoxMonthShamsiConverted.Text = ConvertShamsiMonth(pc.GetMonth(currentDate));
            TextBoxDayInMonthShamsiConverted.Text= pc.GetDayOfMonth(currentDate).ToString();
            TextBoxDayInWeekShamsiConverted.Text = ConvertShamsiDayOfWeek(pc.GetDayOfWeek(currentDate));

        }

        private void ButtonConvertToShamsi_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PersianCalendar pc = new PersianCalendar();
                ComboBoxItem MonthCbi = (ComboBoxItem)(ComboBoxMonthMiladi.SelectedItem);
                ComboBoxItem DayCbi = (ComboBoxItem)(ComboBoxDayMiladi.SelectedItem);

                YearM = Convert.ToInt16(TextBoxYearMiladi.Text);
                MonthM = Convert.ToInt16(MonthCbi.Content);
                DayM = Convert.ToInt16(DayCbi.Content);

                DateTime inputMiladiDaye = new DateTime(YearM, MonthM, DayM);

                TextBoxYearShamsiConverted.Text = pc.GetYear(inputMiladiDaye).ToString();
                TextBoxMonthShamsiConverted.Text = ConvertShamsiMonth(pc.GetMonth(inputMiladiDaye));
                TextBoxDayInMonthShamsiConverted.Text = pc.GetDayOfMonth(inputMiladiDaye).ToString();
                TextBoxDayInWeekShamsiConverted.Text = ConvertShamsiDayOfWeek(pc.GetDayOfWeek(inputMiladiDaye));
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void ConvertToMiladi_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PersianCalendar pc = new PersianCalendar();
                ComboBoxItem MonthCbi = (ComboBoxItem)(ComboBoxMonthShamsi.SelectedItem);
                ComboBoxItem DayCbi = (ComboBoxItem)(ComboBoxDayShamsi.SelectedItem);

                YearS = Convert.ToInt16(TextBoxYearShamsi.Text);
                MonthS = Convert.ToInt16(MonthCbi.Content);
                DayS = Convert.ToInt16(DayCbi.Content);

                DateTime inputShamsiDate = pc.ToDateTime(YearS, MonthS, DayS, 0, 0, 0, 0);

                TextBoxYearMiladiConverted.Text = inputShamsiDate.Year.ToString();
                TextBoxMonthMiladiConverted.Text = ConvertMiladiMonth(inputShamsiDate.Month);
                TextBoxDayInMonthMiladiConverted.Text = inputShamsiDate.Day.ToString();
                TextBoxDayInWeekMiladiConverted.Text = inputShamsiDate.DayOfWeek.ToString();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
